import { Body, Controller, Get, HttpCode, Post } from '@nestjs/common'
import { ApiParam, ApiTags } from '@nestjs/swagger'
import { IGoods } from './goods.interface'
import { GoodsService } from './goods.service'

@ApiTags('Goods')
@Controller('goods')
export class GoodsController {

    constructor(private readonly goodsService: GoodsService) {}

    @Get('allGoodsInfo')
    getAllGoodsInfo() {
        return this.goodsService.allGoodsInfo()
    }

    @Get('deleteAllGoods')
    deleteAllGoods() {
        return this.goodsService.deleteAllGoods()
    }

    @ApiParam({
        name: 'goods',
        description: '物品信息，包含 name, num, tags... 等'
    })
    @Post('addOneGoods')
    @HttpCode(200)
    addOneGoods(@Body() goods: IGoods) {
        return this.goodsService.addOneGoods(goods)
    }

    @ApiParam({
        name: 'key',
        description: '物品 key 信息'
    })
    @Post('checkOneGoods')
    @HttpCode(200)
    checkOneGoods(@Body() keyQuery: { key: string }) {
        return this.goodsService.checkOneGoods(keyQuery)
    }

    @ApiParam({
        name: 'key',
        description: '物品 key 信息'
    })
    @Post('deleteOneGoods')
    @HttpCode(200)
    deleteOneGoods(@Body() keyQuery: { key: string }) {
        return this.goodsService.deleteOneGoods(keyQuery)
    }

    @ApiParam({
        name: 'name',
        description: '物品 name 信息，返回数组'
    })
    @Post('getGoodsByName')
    @HttpCode(200)
    getGoodsByName(@Body() nameQuery: { name: string }) {
        return this.goodsService.getGoodsByName(nameQuery)
    }

    @ApiParam({
        name: 'goods',
        description: '物品信息，包含 name, num, tags... 等'
    })
    @Post('updateOneGoods')
    @HttpCode(200)
    updateOneGoods(@Body() goods: IGoods) {
        return this.goodsService.updateOneGoods(goods)
    }

    @ApiParam({
        name: 'keys',
        description: '物品 key 信息数组'
    })
    @Post('deleteGoodsByKeys')
    @HttpCode(200)
    deleteGoodsByKeys(@Body() keysQuery: { keys: string[] }) {
        console.log(keysQuery)
        return this.goodsService.deleteGoodsByKeys(keysQuery.keys)
    }
}
